/*
 * @Author: 刘润泽
 * @Date: 2022-11-08 18:12:28
 * @LastEditors: 刘润泽
 * @LastEditTime: 2023-02-23 17:47:59
 * @Description: 
 */
package server.business.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import server.business.pojo.MsgText;
import server.business.service.MsgTextService;
import server.business.mapper.MsgTextMapper;

import java.util.List;

import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Galaxy
 * @description 针对表【msg_text】的数据库操作Service实现
 * @createDate 2022-11-08 12:46:24
 */
@Service("msgTextService")
public class MsgTextServiceImpl extends ServiceImpl<MsgTextMapper, MsgText>
                implements MsgTextService {
        @Autowired
        private MsgTextMapper msgTextMapper;

        /**
         *
         * @param currentPage
         * @param pageSize
         * @param bloodInformation
         * @return
         */
        @Override
        @SuppressWarnings("")
        public IPage<MsgText> getPage(int currentPage, int pageSize, MsgText msgText) {
                LambdaQueryWrapper<MsgText> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.eq(Strings.isNotBlank(msgText.getState()), MsgText::getState, msgText.getState())
                                .eq(msgText.getIsDeleted() != null, MsgText::getIsDeleted,
                                                msgText.getIsDeleted());
                IPage<MsgText> page = new Page<>(currentPage, pageSize);
                msgTextMapper.selectPage(page, queryWrapper);
                return page;
        }

        /**
         * 根据医生编号查询到相关通知
         */
        @Override
        public List<MsgText> getTextByDoctorJobnum(String doctorJobnum) {
                LambdaQueryWrapper<MsgText> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.eq(Strings.isNotBlank(doctorJobnum), MsgText::getDoctorJobnum, doctorJobnum)
                                .eq(MsgText::getState, "未读");
                List<MsgText> msgTexts = msgTextMapper.selectList(queryWrapper);
                return msgTexts;
        }

        /**
         * 添加消息记录
         * 
         */
        @Override
        public void addTextInfo(MsgText msgText) {
                msgTextMapper.insert(msgText);
        }

        /**
         * 设置消息阅读状态
         */
        @Override
        public void setReadState(MsgText msgText) {
                LambdaUpdateWrapper<MsgText> updateWrapper = new LambdaUpdateWrapper<>();
                updateWrapper.eq(MsgText::getId, msgText.getId());
                updateWrapper.set(MsgText::getState, msgText.getState())
                                .set(MsgText::getReadTime, msgText.getReadTime());
                int result = msgTextMapper.update(null, updateWrapper);
                System.out.println("result" + result);
        }

        /**
         * 设置消息删除状态
         *
         * @param id
         * @param doctorJobNum
         * @param isDeleted
         * @return
         */
        @Override
        public void setIsDeleted(MsgText msgText) {
                LambdaUpdateWrapper<MsgText> updateWrapper = new LambdaUpdateWrapper<>();
                updateWrapper.eq(MsgText::getId, msgText.getId());
                updateWrapper.set(MsgText::getIsDeleted, msgText.getIsDeleted())
                                .set(MsgText::getDeletedTime, msgText.getDeletedTime());
                int result = msgTextMapper.update(null, updateWrapper);
                System.out.println("result" + result);
        }
}
